$(document).ready(function(){
    
    let $username = $('#username');
    let $password = $('#password');
    let $cofirm_password = $('#confirm_password');
    let $name = $('#name')
    let $studentid = $('#studentid')
    let $gender = $('#gender')


    $('#submit').click(function (){
        if($username.val() && $password.val() && $name.val() && $studentid.val()) {
            if($cofirm_password.val() == $password.val()){
                let userinfo = {
                    username: $username.val(),
                    password: $password.val(),
                    name: $name.val(),
                    studentid: $studentid.val(),
                    gender: $gender.val()
                };
                console.log(userinfo);
        
                $.ajax({
                    type: 'POST',
                    //  url: 'http://dorm.zhangqx.com/api/register',
                    url: 'http://101.133.131.59:8001/api/register',
                    // url: '/api/register',
                    data: userinfo,
                    success: function(response) {
                        console.log(response);
                        alert(response.message);
                        if(response.status == 1){
                            // setTimeout("window.location.href = '/login'", 5000);
                            setTimeout("window.location.href = './../login/login.html'", 5000);
                        }
                    },
                    error: function() {
                        alert('error register');
                    }
                });        
            }
            else {
                alert("Inconsistent passwords, please check again!")
            }
        }
        else {
            alert("Incomplete form!")
        }

    });
});